import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_web/webview_flutter_web.dart';

import 'HomePage/main.dart';
import 'SearchPage/main.dart';

void main() {
  // 因为要改变GlobalSetting，所以最好在程序入口加载文件

  WidgetsFlutterBinding.ensureInitialized();
  WebViewPlatform.instance = WebWebViewPlatform();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var mode;

  @override
  void initState() {
    mode = ThemeMode.light;
    super.initState();
  }

  void setTheme(){
    setState(() {
      mode = mode == ThemeMode.light ? ThemeMode.dark : ThemeMode.light ;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      themeMode: mode,
      title: "MOLI",
      initialRoute: '/',
      routes: {
        '/': (context)=>HomePage(setTheme),
        '/search': (context)=>SearchPage(
          backgroundImage: "https://th.bing.com/th/id/OIP.YsDP7cyitcDmd9n6lVR_5wHaQB?rs=1&pid=ImgDetMain",
          title: "MOLI一下，你就知道",
        ),
      },
    );
  }
}